package com.aw.baselib.widgets.font;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.widget.TextView;

import com.aw.baselib.base.AwBaseApplication;

/**
 * @author : hzw
 * https://blog.csdn.net/yuanxw44/article/details/80019501
 */
@SuppressLint("AppCompatCustomView")
public class AwTvRegularRed extends TextView {

    public AwTvRegularRed(Context context, AttributeSet attrs) {
        super(context, attrs);
        setTypeface(AwBaseApplication.getInstance().getTypefaceRegular());
    }


    @Override
    public void setText(CharSequence text, BufferType type) {
        if(text != null && text.length() >= 1) {
            SpannableString ss = new SpannableString(text);
            ss.setSpan(new ForegroundColorSpan(Color.RED), text.length() - 1, text.length(),
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            super.setText(ss, type);
        } else {
            super.setText(text, type);
        }
    }
}
